﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OnlineCourse.Model;
using OnlineCourse.Model.Entity;
using OnlineCourse.Services;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace OnlineCourse.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CouponController : ControllerBase
    {
        private CouponService _home;
        public CouponController(ApplicationDbContext db)
        {
            _home = new CouponService(db);
        }
        /// <summary>
        /// 增加一张优惠券
        /// </summary>
        /// <param name="Title"></param>
        /// <param name="Price"></param>
        /// <param name="Number"></param>
        /// <returns></returns>
        [HttpPost("AddCoupon")]
        public IActionResult Add(string Title, decimal Price, int Number)
        {
            var a = _home.Add(Title, Price, Number);
            return Ok(a);
        }
        /// <summary>
        /// 删除一张优惠券
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("Delete")]
        public IActionResult Delete(Guid id)
        {
            var a = _home.Delete(id);
            return Ok(a);
        }
        /// <summary>
        /// 单个优惠券明细查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("SingelQuery")]
        public IActionResult Get(Guid id)
        {
            var a = _home.Get(id);
            return Ok(a);
        }
        /// <summary>
        /// 增加指定的优惠券数量
        /// </summary>
        /// <param name="id"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        [HttpPost("Add")]
        public IActionResult Ad(Guid id, int number)
        {
            var a = _home.Ad(id, number);
            return Ok(a);
        }
        /// <summary>
        /// 减少指定的券数量
        /// </summary>
        /// <param name="id"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        [HttpDelete("Reduce")]
        public IActionResult Reduce(Guid id, int number)
        {
            var a = _home.Reduce(id, number);
            return Ok(a);
        }
    }
}